package com.alpha.service.impl;

import com.alpha.mapper.SysJobLogMapper;
import com.alpha.pojo.dto.SysJobDTO;
import com.alpha.pojo.dto.SysJobLogDTO;
import com.alpha.service.SysJobLogService;
import com.alpha.utils.PageUtils;
import com.alpha.utils.msg.QueryReqBean;
import com.alpha.utils.msg.QueryRespBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 定时任务调度日志信息 服务层
 *
 * @author
 */
@Slf4j
@Service
public class SysJobLogServiceImpl implements SysJobLogService {
    @Autowired
    private SysJobLogMapper jobLogMapper;

    /**
     * 获取quartz调度器日志的计划任务
     *
     * @param jobLog 调度日志信息
     * @return 调度任务日志集合
     */
    @Override
    public List<SysJobLogDTO> selectJobLogList(SysJobLogDTO jobLog) {
        return jobLogMapper.selectJobLogList(jobLog);
    }


    @Override
    public QueryRespBean<SysJobLogDTO> searchByPage(QueryReqBean<SysJobLogDTO> queryReqBean) {
        QueryRespBean<SysJobLogDTO> queryRespBean = new QueryRespBean<>();
        try {
            PageHelper.startPage(PageUtils.startPage(queryReqBean.getPageParameter()));
            SysJobLogDTO searchParams = queryReqBean.getSearchParams();
            Page<SysJobLogDTO> dataList = jobLogMapper.searchByPage(searchParams);
            queryRespBean.setResult(dataList);
            return queryRespBean;
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    /**
     * 通过调度任务日志ID查询调度信息
     *
     * @param jobLogId 调度任务日志ID
     * @return 调度任务日志对象信息
     */
    @Override
    public SysJobLogDTO selectJobLogById(Long jobLogId) {
        return jobLogMapper.selectJobLogById(jobLogId);
    }

    /**
     * 新增任务日志
     *
     * @param jobLog 调度日志信息
     */
    @Override
    public void addJobLog(SysJobLogDTO jobLog) {
        jobLogMapper.insertJobLog(jobLog);
    }

    /**
     * 批量删除调度日志信息
     *
     * @param logIds 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteJobLogByIds(Long[] logIds) {
        return jobLogMapper.deleteJobLogByIds(logIds);
    }

    /**
     * 删除任务日志
     *
     * @param jobId 调度日志ID
     */
    @Override
    public int deleteJobLogById(Long jobId) {
        return jobLogMapper.deleteJobLogById(jobId);
    }

    /**
     * 清空任务日志
     */
    @Override
    public void cleanJobLog() {
        jobLogMapper.cleanJobLog();
    }
}
